package com.zoe.tree.entity;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.Set;
import java.util.TreeSet;

/**
 * @author zbg
 * @date 2023/06/19
 * @description $description
 */
@Data
@TableName(value = "dept_ancestors")
public class DeptAncestors implements Comparable<DeptAncestors> {
    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField(value = "pid")
    private Long pid;

    /**
     * 祖籍列表
     */
    @TableField(value = "ancestors")
    private String ancestors;

    /**
     * 排序
     */
    @TableField(value = "sort")
    private Integer sort;

    /**
     * 名字
     */
    @TableField(value = "`name`")
    private String name;

    /**
     * 名字
     */
    @TableField(exist = false)
    private Long nextId;

    @TableField(exist = false)
    private Set<DeptAncestors> children = new TreeSet<>();

    @Override
    public int compareTo(DeptAncestors o) {
        if (ObjectUtil.equal(this.getSort(), o.getSort())) {
            return 1;
        }
        return this.getSort() - o.getSort();
    }

    public void addChildren(DeptAncestors deptAncestors) {
        children.add(deptAncestors);
    }
}